//
// GNS_SingLayer.cpp
// GameHall
//
// Created by mr.l on 16/2/3.
//
//

#include "GNS_SingLayer.h"
#include "cocostudio/CocoStudio.h"
#include "ui/CocosGUI.h"
#include "GNS_PlayerMgr.h"
USING_NS_CC;
using namespace cocostudio::timeline;
using namespace ui;

#define winsize Director::getInstance()->getVisibleSize()

GNS_SingLayer::GNS_SingLayer()
{

}

GNS_SingLayer::~GNS_SingLayer()
{
    
}

GNS_SingLayer* GNS_SingLayer::createLayer()
{
    auto pGNS_SingLayer = GNS_SingLayer::create();
    auto pScene = Director::getInstance()->getRunningScene();
    if (!pScene)
        return 0;
    pScene->addChild(pGNS_SingLayer);
    return pGNS_SingLayer;
}

bool GNS_SingLayer::init()
{
    if ( !GNS_YJFLayer::init() )
    {
        return false;
    }
    return true;
}

void GNS_SingLayer::SetNodeName(std::string CsbName)
{
	m_RootNode = Loadcsb(CsbName);
	addChild(m_RootNode, 11);

	auto pBackBtn = static_cast<Button*>(m_RootNode->getChildByName("Button_4"));
    pBackBtn->setTag(1);
    pBackBtn->addTouchEventListener(CC_CALLBACK_2(GNS_SingLayer::BtnCallBack, this)); 

	auto noticText = static_cast<Text*>(m_RootNode->getChildByName("Text_1"));
	noticText->setString(GTOU(GNS_PlayerMgr::GetInstance()->getMyNotice()));
}


void GNS_SingLayer::updateNoticeText()
{ 
	auto noticText = static_cast<Text*>(m_RootNode->getChildByName("Text_1"));
	if (nullptr != noticText)
	{
		noticText->setString(GTOU(GNS_PlayerMgr::GetInstance()->getMyNotice()));
	}
}

void GNS_SingLayer::BtnCallBack(cocos2d::Ref *pSender, ui::Widget::TouchEventType type){
    if (type==ui::Widget::TouchEventType::ENDED) {
        auto pButton = (Button*)pSender;
        int BtnTag = pButton->getTag();
        switch (BtnTag) {
            case 1:
            {
				Show(false);
                break;
            }
            default:
                break;
        }
    }
}

